<?php

// +----------------------------------------------------------------------
// | 消息模板服务层
// +----------------------------------------------------------------------
// | 主要服务于消息模板
// +----------------------------------------------------------------------
// | 错误编码头 216xxx
// +----------------------------------------------------------------------
namespace common\service;

use support\SingletonTrait;


class MessageTemplateService
{

    // 单例工具
    use SingletonTrait;

    /**
     * 渲染模板消息
     * @param array $param
     * @param int $templateId
     * @return mixed
     * @throws \Exception
     */
    public function renderMessage(array $param, int $templateId)
    {
        $requestData = [
            'param' => $param,
            'template_id' => $templateId,
        ];
        return teamones_request('teamones-im', 'oauth/render_message_template', $requestData)['data'];
    }

    /**
     * 获得工序任务执行人通知模板配置
     * @return int
     */
    public function getNotifyStepTaskExecutorTemplateId()
    {
        $messageTemplateId = OptionsService::getInstance()->getOptionsConfigItemData('message_notify_template_config', 'step_task_executor_template_id');
        return (int)$messageTemplateId;
    }

    /**
     * 获得分配任务通知消息模板id
     * @return int
     */
    public function getSetTaskExecutorMessageTemplateId()
    {
        $templateId = OptionsService::getInstance()->getOptionsConfigItemData('message_notify_template_config', 'set_task_executor');
        return (int)$templateId;
    }
}
